package com.dmxh.controller;

import com.dmxh.result.Result;
import com.dmxh.service.ContentService;
import com.dmxh.vo.ContentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/content")
public class ContentController {
    /*广告管理*/
    @Autowired
    private ContentService contentService;

    @GetMapping("/queryContents")
    public Result queryContents(Integer pageNum,Integer pageSize,ContentVo contentVo){
//        Page page = new Page();
//        page.setCurrent(pageNum);
//        page.setSize(pageSize);
//
//        LambdaQueryWrapper<TbContent> wrapper = new LambdaQueryWrapper<>();
//        wrapper.like(contentVo.getTitle()!=null,TbContent::getTitle,contentVo.getTitle());
//
//        wrapper.orderByDesc(TbContent::getSortOrder);
        return Result.ok().setData(this.contentService.queryAllContents(pageNum,pageSize,contentVo));
    }

    @PostMapping("/saveContents")
    public Result saveContents(@RequestBody ContentVo contentVo){
        return Result.ok().setData(this.contentService.saveContents(contentVo));
    }

    @DeleteMapping("/deleteContents")
    public Result deleteContents(@RequestParam Long id){
        return Result.ok().setData(this.contentService.delContents(id));
    }

    @PutMapping("/updateContents")
    public Result updateContents(@RequestBody ContentVo contentVo){
        return Result.ok().setData(this.contentService.updateContents(contentVo));
    }
}
